package model;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Anlage extends ModelID implements Comparable<Anlage>{
	
	private String beschreibung;
	private String pfad;
	private Date timestamp;
	
	
	
	
	public Anlage(String beschreibung, String pfad, Date timestamp) {
		setBeschreibung(beschreibung);
		setPfad(pfad);
		setTimestamp(timestamp);
	}
	
	public String getBeschreibung() {
		return beschreibung;
	}
	public String getPfad() {
		return pfad;
	}
	public Date getTimestamp() {
		return  (Date) timestamp.clone();
	}
	public void setBeschreibung(String beschreibung) {
		if(beschreibung == null || beschreibung.trim().length() < 1) throw new IllegalArgumentException("Beschreibung darf nicht null sein!");
			this.beschreibung = beschreibung;
	}
	
	public void setPfad(String pfad) {
		if(pfad == null || pfad.trim().length() < 1) throw new IllegalArgumentException("Pfad darf nicht null sein!");
			this.pfad = pfad;
	}
	public void setTimestamp(Date timestamp) {
		if(timestamp == null) throw new IllegalArgumentException("Timestamp darf nicht null sein!");
		this.timestamp = (Date) timestamp.clone();
	}

	@Override
	public int compareTo(Anlage o) {
	    int i;
		i = this.timestamp.compareTo(o.getTimestamp());

		return i;
		
	}

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = super.hashCode();
    result = prime * result + ((beschreibung == null) ? 0 : beschreibung.hashCode());
    result = prime * result + ((pfad == null) ? 0 : pfad.hashCode());
    result = prime * result + ((timestamp == null) ? 0 : timestamp.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");  
    
    if (this == obj)
      return true;
    if (!super.equals(obj))
      return false;
    if (getClass() != obj.getClass())
      return false;
    Anlage other = (Anlage) obj;
    if (beschreibung == null) {
      if (other.beschreibung != null)
        return false;
    } else if (!beschreibung.equals(other.beschreibung))
      return false;
    if (pfad == null) {
      if (other.pfad != null)
        return false;
    } else if (!pfad.equals(other.pfad))
      return false;
    if (timestamp == null) {
      if (other.timestamp != null)
        return false;
    } else if (!sdf.format(timestamp).equals(sdf.format(other.timestamp)))
      return false;
    return true;
  }




	

}
